package com.tuoyu.peopletest.model;


import com.tuoyu.peopletest.entity.DataBean;

import org.litepal.LitePal;

import java.util.List;

/**
 * 呼吸训练数据
 */
public class DataModel {


    private DataModel() {

    }
    public static DataModel get() {
        return new DataModel();
    }

    /**
     * 保存测试数据
     * @param bean
     */
    public void save(DataBean bean){
         bean.save();
    }

//    public void saveAndDelete(XjtxbasspBean bean){
//        delectBeanByLocalUUID(bean.local_uuid);
//        bean.save();
//    }

    /**
     * 编号唯一
     * @param bean
     */
    public void saveAndDelete02(DataBean bean){
        delectBeanByNumber(bean.number);
        bean.save();
    }

    public void delectBeanByNumber(String number){
        LitePal.deleteAll(DataBean.class," number = ? ", number);
    }

//    public void delectBeanByLocalUUID(String local_uuid){
//        LitePal.deleteAll(XjtxbasspBean.class," local_uuid = ? ", local_uuid);
//    }
//
//
//    public XjtxbasspBean getDataByLocalUuid(String local_uuid) {
//        List<XjtxbasspBean> list = LitePal.where(" local_uuid = ? ", local_uuid).find(XjtxbasspBean.class);
//        return list.size() > 0 ? list.get(0) : null;
//    }

//    public List<XjtxbasspBean> getList(int page, int pageMax) {
//        int limit = (page - 1) * pageMax;
//        return LitePal
//                .order("time desc")
//                .limit(pageMax)
//                .offset(limit)
//                .find(XjtxbasspBean.class);
//    }

    public List<DataBean> getList(long startTime, long endTime) {
        return LitePal
                .where("time >= ? and time <= ? ",startTime+"",endTime+"")
                .order("time desc")
                .find(DataBean.class);
    }

    public List<DataBean> getListByNumber(String number) {
        List<DataBean> list = LitePal.where(" number = ? ", number).find(DataBean.class);
        return list;
    }





}
